package com.xzm.project.ui.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * author : xuzongmeng
 * date   : 2019/2/19.
 * desc   : 描述
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected final String TAG = this.getClass().getSimpleName();
    public Context mContext;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        RecyclerView  recyclerView;
//        recyclerView.addItemDecoration();
        mContext = this;
        if (getLayoutID() != 0) {
            setContentView(getLayoutID());
        } else {
            setContentView(getView());
        }
        initView(savedInstanceState);
        initData();
        initListener();
    }
    /**
     * 获取子Layout
     */
    protected  int getLayoutID(){
        return 0;
    }

    /**
     * 获取子View
     */
    protected  View getView(){
         return null;
    }

//
//    private View  getRootView(){
//        rootView = new LinearLayout(mContext);
//        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.MATCH_PARENT);
//        rootView.setLayoutParams(layoutParams);
////        rootView.setBackgroundColor(ResUtils.getColor(R.color.Green));
//        rootView.setOrientation(LinearLayout.VERTICAL);
//        return rootView;
//    }
//
    /**
     * 初始化子View
     */
    protected void initView(Bundle savedInstanceState) {
    }

    /**
     * 初始化子类数据
     */
    public void initData() {
    }

    /**
     * 添加事件监听
     */
    protected void initListener() {
    }


    /**
     * 禁止app字体使用系统字体
     */
    @SuppressLint("ObsoleteSdkInt")
    @SuppressWarnings("deprecation")
    @Override
    public Resources getResources() {
        Resources resources = super.getResources();
        Configuration newConfig = resources.getConfiguration();
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        if (resources != null && newConfig.fontScale != 1) {
            newConfig.fontScale = 1;
            if (Build.VERSION.SDK_INT >= 17) {
                Context configurationContext = createConfigurationContext(newConfig);
                resources = configurationContext.getResources();
                displayMetrics.scaledDensity = displayMetrics.density * newConfig.fontScale;
            } else {
                resources.updateConfiguration(newConfig, displayMetrics);
            }
        }
        return resources;
    }


}
